home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / IEditor / Generators / E / strings.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-17  |  7.6 KB  |  340 lines

  1. /// Includes
  2. #define INTUI_V36_NAMES_ONLY
  3.  
  4. #include <exec/nodes.h>                 // exec
  5. #include <exec/lists.h>
  6. #include <exec/types.h>
  7. #include <dos/dos.h>                    // dos
  8. #include <libraries/gadtools.h>         // libraries
  9. #include <clib/exec_protos.h>           // protos
  10. #include <clib/dos_protos.h>
  11. #include <pragmas/exec_pragmas.h>       // pragmas
  12. #include <pragmas/dos_pragmas.h>
  13.  
  14. #include <string.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <ctype.h>
  18.  
  19. #include "DEV_IE:Generators/defs.h"
  20. #include "DEV_IE:Include/IEditor.h"
  21. #include "DEV_IE:Generators/C/Protos.h"
  22. ///
  23.  
  24.  
  25. /// CountArray
  26. UWORD CountArray( UBYTE **Array )
  27. {
  28.     UWORD   cnt = 0;
  29.  
  30.     while( *Array++ )
  31.     cnt += 1;
  32.  
  33.     return( cnt );
  34. }
  35. ///
  36. /// CmpArrays
  37. BOOL CmpArrays( UBYTE **First, struct MinList *Second )
  38. {
  39.     UWORD                   num, cnt;
  40.     struct GadgetScelta    *gs;
  41.  
  42.     num = CountArray( First );
  43.  
  44.     gs = Second->mlh_Head;
  45.     cnt = 0;
  46.     while( gs->gs_Node.ln_Succ ) {
  47.     cnt += 1;
  48.     gs = gs->gs_Node.ln_Succ;
  49.     }
  50.  
  51.     if( num != cnt )
  52.     return( FALSE );
  53.  
  54.     gs = Second->mlh_Head;
  55.  
  56.     for( cnt = 0; cnt < num; cnt++ ) {
  57.     if( strcmp( *First++, gs->gs_Testo ))
  58.         return( FALSE );
  59.     gs = gs->gs_Node.ln_Succ;
  60.     }
  61.  
  62.     return( TRUE );
  63. }
  64. ///
  65. /// FindString
  66. struct StringNode *FindString( struct MinList *List, UBYTE *String )
  67. {
  68.     struct StringNode  *str;
  69.  
  70.     for( str = List->mlh_Head; str->Next; str = str->Next )
  71.     if(!( strcmp( str->String, String )))
  72.         return( str );
  73.  
  74.     return( NULL );
  75. }
  76. ///
  77. /// FindArray
  78. struct ArrayNode *FindArray( struct MinList *List, struct MinList *Array )
  79. {
  80.     struct ArrayNode   *ar;
  81.  
  82.     for( ar = List->mlh_Head; ar->Next; ar = ar->Next )
  83.     if( CmpArrays( ar->Array, Array ))
  84.         return( ar );
  85.  
  86.     return( NULL );
  87. }
  88. ///
  89. /// AddString
  90. BOOL AddString( struct MinList *List, UBYTE *String )
  91. {
  92.     struct StringNode  *str;
  93.  
  94.     if(!( FindString( List, String ))) {
  95.     if(!( str = AllocMem( sizeof( struct StringNode ), 0L )))
  96.         return( FALSE );
  97.  
  98.     AddTail(( struct List * )List, ( struct Node * )str );
  99.  
  100.     str->String = String;
  101.     }
  102.  
  103.     return( TRUE );
  104. }
  105. ///
  106. /// AddArray
  107. BOOL AddArray( struct GenFiles *Files, struct MinList *Items )
  108. {
  109.     struct ArrayNode       *ar;
  110.     struct GadgetScelta    *gs;
  111.     UBYTE                 **Array;
  112.     UBYTE                   size = 4;
  113.  
  114.     if(!( FindArray( &Files->Arrays, Items ))) {
  115.     if(!( ar = AllocMem( sizeof( struct ArrayNode ), 0L )))
  116.         return( FALSE );
  117.  
  118.     AddTail(( struct List * )&Files->Arrays, ( struct Node * )ar );
  119.  
  120.     gs = Items->mlh_Head;
  121.     while( gs = gs->gs_Node.ln_Succ )
  122.         size += 4;
  123.  
  124.     if(!( Array = AllocVec( size, 0L )))
  125.         return( FALSE );
  126.  
  127.     ar->Array = Array;
  128.  
  129.     for( gs = Items->mlh_Head; gs->gs_Node.ln_Succ; gs = gs->gs_Node.ln_Succ ) {
  130.  
  131.         *Array++ = gs->gs_Testo;
  132.  
  133.         if(!( AddString( &Files->Strings, gs->gs_Testo ))) {
  134.         FreeVec( ar->Array );
  135.         return( FALSE );
  136.         }
  137.     }
  138.  
  139.     *Array = NULL;
  140.  
  141.     }
  142.  
  143.     return( TRUE );
  144. }
  145. ///
  146. /// PutLabels
  147. void PutLabels( struct IE_Data *IE, struct GenFiles *Files )
  148. {
  149.     UWORD               cnt;
  150.     struct StringNode  *str;
  151.     STRPTR              label;
  152.  
  153.     label = ( IE->SrcFlags & LOCALIZE ) ? "MSG_STRING_%ld" : "String%ld";
  154.  
  155.     for( str = Files->Strings.mlh_Head, cnt = 0; str->Next; str = str->Next ) {
  156.     sprintf( str->Label, label, cnt );
  157.     cnt += 1;
  158.     }
  159.  
  160.     struct ArrayNode   *ar;
  161.  
  162.     for( ar = Files->Arrays.mlh_Head, cnt = 0; ar->Next; ar = ar->Next ) {
  163.     sprintf( ar->Label, "Array%ld", cnt );
  164.     cnt += 1;
  165.     }
  166. }
  167. ///
  168. /// ProcessStrings
  169. BOOL ProcessStrings( struct IE_Data *IE, struct GenFiles *Files )
  170. {
  171.     struct WindowInfo  *wnd;
  172.     BOOL                loc;
  173.  
  174.     if(( IE->ScreenData->Title[0] ) && ( IE->flags_2 & GENERASCR ))
  175.     if(!( AddString( &Files->Strings, IE->ScreenData->Title )))
  176.         return( FALSE );
  177.  
  178.     loc = ( IE->SrcFlags & LOCALIZE ) ? TRUE : FALSE;
  179.  
  180.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  181.  
  182.     LONG   add;
  183.  
  184.     add = loc ? ( wnd->wi_Tags & W_LOC_TITLE ) : TRUE;
  185.  
  186.     if(( wnd->wi_Titolo[0] ) && ( add ))
  187.         if(!( AddString( &Files->Strings, wnd->wi_Titolo )))
  188.         return( FALSE );
  189.  
  190.     if( loc )
  191.         add = wnd->wi_Tags & W_LOC_SCRTITLE;
  192.     else
  193.         add = TRUE;
  194.  
  195.     if(( wnd->wi_TitoloSchermo[0] ) && ( add ))
  196.         if(!( AddString( &Files->Strings, wnd->wi_TitoloSchermo )))
  197.         return( FALSE );
  198.  
  199.  
  200.  
  201.     if( loc )
  202.         add = wnd->wi_Tags & W_LOC_GADGETS;
  203.     else
  204.         add = TRUE;
  205.  
  206.     if( add ) {
  207.         struct GadgetBank  *bank;
  208.  
  209.         ProcessGadgets( Files, &wnd->wi_Gadgets );
  210.  
  211.         for( bank = wnd->wi_GBanks.mlh_Head; bank->Node.ln_Succ; bank = bank->Node.ln_Succ )
  212.         ProcessGadgets( Files, &bank->Storage );
  213.     }
  214.  
  215.     struct ITextNode   *txt;
  216.  
  217.     if( loc )
  218.         add = wnd->wi_Tags & W_LOC_TEXTS;
  219.     else
  220.         add = TRUE;
  221.  
  222.     if( add )
  223.         for( txt = wnd->wi_ITexts.mlh_Head; txt->itn_Node.ln_Succ; txt = txt->itn_Node.ln_Succ )
  224.         if( txt->itn_Text[0] )
  225.             if(!( AddString( &Files->Strings, txt->itn_Text )))
  226.             return( FALSE );
  227.  
  228.     if( loc )
  229.         add = wnd->wi_Tags & W_LOC_MENUS;
  230.     else
  231.         add = TRUE;
  232.  
  233.     if( add ) {
  234.         struct MenuTitle   *menu;
  235.         for( menu = wnd->wi_Menus.mlh_Head; menu->mt_Node.ln_Succ; menu = menu->mt_Node.ln_Succ ) {
  236.  
  237.         if( menu->mt_Text[0] )
  238.             if(!( AddString( &Files->Strings, menu->mt_Text )))
  239.             return( FALSE );
  240.  
  241.         struct _MenuItem *item;
  242.         for( item = menu->mt_Items.mlh_Head; item->min_Node.ln_Succ; item = item->min_Node.ln_Succ ) {
  243.  
  244.             if(( item->min_Text[0] ) && (!( item->min_Flags & M_BARLABEL )))
  245.             if(!( AddString( &Files->Strings, item->min_Text )))
  246.                 return( FALSE );
  247.  
  248.             if( item->min_CommKey[0] )
  249.             if(!( AddString( &Files->Strings, item->min_CommKey )))
  250.                 return( FALSE );
  251.  
  252.             struct MenuSub *sub;
  253.             for( sub = item->min_Subs.mlh_Head; sub->msn_Node.ln_Succ; sub = sub->msn_Node.ln_Succ ) {
  254.  
  255.             if(( sub->msn_Text[0] ) && (!( sub->msn_Flags & M_BARLABEL )))
  256.                 if(!( AddString( &Files->Strings, sub->msn_Text )))
  257.                 return( FALSE );
  258.  
  259.             if( sub->msn_CommKey[0] )
  260.                 if(!( AddString( &Files->Strings, sub->msn_CommKey )))
  261.                 return( FALSE );
  262.             }
  263.         }
  264.         }
  265.     }
  266.  
  267.     }
  268.  
  269.     PutLabels( IE, Files );
  270.  
  271.     return( TRUE );
  272. }
  273. ///
  274. /// ProcessGadgets
  275. BOOL ProcessGadgets( struct GenFiles *Files, struct MinList *Gadgets )
  276. {
  277.     struct GadgetInfo  *gad;
  278.  
  279.     for( gad = Gadgets->mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ ) {
  280.  
  281.     if(( gad->g_Kind < MIN_IEX_ID ) && ( gad->g_Titolo[0] ))
  282.         if(!( AddString( &Files->Strings, gad->g_Titolo )))
  283.         return( FALSE );
  284.  
  285.     switch( gad->g_Kind ) {
  286.  
  287.         case MX_KIND:
  288.         case CYCLE_KIND:
  289.         if(!( AddArray( Files, &gad->g_Scelte )))
  290.             return( FALSE );
  291.         break;
  292.  
  293.         case LISTVIEW_KIND:
  294.         {
  295.             struct GadgetScelta *gs;
  296.             for( gs = gad->g_Scelte.mlh_Head; gs->gs_Node.ln_Succ; gs = gs->gs_Node.ln_Succ )
  297.             if(!( AddString( &Files->Strings, gs->gs_Testo )))
  298.                 return( FALSE );
  299.         }
  300.         break;
  301.  
  302.         case TEXT_KIND:
  303.         case STRING_KIND:
  304.         if( *((UBYTE *)(gad->g_ExtraMem)) )
  305.             if(!( AddString( &Files->Strings, gad->g_ExtraMem )))
  306.             return( FALSE );
  307.         break;
  308.  
  309.         case NUMBER_KIND:
  310.         if(( ((struct NK)(gad->g_Data)).Format[0] ) && ( strcmp( ((struct NK)(gad->g_Data)).Format, "%ld" )))
  311.             if(!( AddString( &Files->Strings, ((struct NK)(gad->g_Data)).Format )))
  312.             return( FALSE );
  313.         break;
  314.  
  315.         case SLIDER_KIND:
  316.         if( ((struct SlK)(gad->g_Data)).Format[0] )
  317.             if(!( AddString( &Files->Strings, ((struct SlK)(gad->g_Data)).Format )))
  318.             return( FALSE );
  319.         break;
  320.     }
  321.     }
  322. }
  323. ///
  324. /// FreeStrings
  325. void FreeStrings( struct GenFiles *Files )
  326. {
  327.     struct StringNode  *Str;
  328.     struct ArrayNode   *Array;
  329.  
  330.     while( Str = RemHead(( struct List * )&Files->Strings ))
  331.     FreeMem( Str, sizeof( struct StringNode ));
  332.  
  333.     while( Array = RemHead(( struct List * )&Files->Arrays )) {
  334.     FreeVec( Array->Array );
  335.     FreeMem( Array, sizeof( struct ArrayNode ));
  336.     }
  337. }
  338. ///
  339.  
  340.